package org.base.common.deserializer;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;

import java.io.IOException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * @author He mingliang
 * @date 2020/5/9
 */
public class LocalDateDeserializer extends com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer {
    protected LocalDateDeserializer() {
        super();
    }

    public LocalDateDeserializer(DateTimeFormatter dtf) {
        super(dtf);
    }

    public LocalDateDeserializer(com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer base, DateTimeFormatter dtf) {
        super(base, dtf);
    }

    protected LocalDateDeserializer(com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer base, Boolean leniency) {
        super(base, leniency);
    }

    @Override
    protected com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer withDateFormat(DateTimeFormatter dtf) {
        return new LocalDateDeserializer(this, dtf);
    }

    @Override
    public LocalDate deserialize(JsonParser parser, DeserializationContext context) throws IOException {
        LocalDate localDate = super.deserialize(parser, context);
//        if (localDate != null) {
//            final Integer offset = TimeZoneOffsetHolder.getOffset();
//            if (offset != null && offset > 0) {
//                localDate = localDate.atStartOfDay().minus(offset, ChronoUnit.HOURS).toLocalDate();
//            }
//        }
        return localDate;
    }
}
